package com.mmx.extension;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.mmx.domain.bean.NodeData;
import com.mmx.domain.bean.NodeProperties;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @desc: 审批人抽象接口
 * @author: liushuai
 * @date: 2023/2/8 10:27
 */
public abstract class AbstractApprover {

    public List<String> getApprover(NodeData nodeData, Map<String, Object> variables){
        NodeProperties properties = nodeData.getProperties();
        //优先使用固定用户
        if(StrUtil.isNotEmpty(properties.getAssignee())){
            String[] assignees = properties.getAssignee().split(",");
            return ListUtil.toList(assignees);
        }
        List<String> assigneeList = this.customApprover(nodeData, variables);
        if(CollectionUtil.isEmpty(assigneeList)){
            throw new IllegalArgumentException("The approver does not exist");
        }
        return  assigneeList;
    }

    /**
     * 自定义审批人
     * @param nodeData
     * @param variables
     * @return: java.util.List<java.lang.String>
     * @Author: liushuai
     * @Date: 2023/2/8 10:44
     */
    public abstract List<String> customApprover(NodeData nodeData, Map<String, Object> variables);
}
